package cn.gson.work.model.pojos;

import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.*;
import java.util.Collection;
import java.util.Date;
import java.util.Objects;

@Entity
@Table(name = "USER_", schema = "WORK", catalog = "")
public class User {
    private long userNo;
    private String userName;
    private String sex;
    private Date birthday;
    private String remarks;
    private String isMsg;
    private Long userPhone;
    private Position position;
    private Dept dept;
    private Collection<Project> projectsByUserNo;
    private Collection<Budget> budgetsByBId;


    @Id
    @Column(name = "USER_NO")
    public long getUserNo() {
        return userNo;
    }

    public void setUserNo(long userNo) {
        this.userNo = userNo;
    }

    @Basic
    @Column(name = "USER_NAME")
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    @Basic
    @Column(name = "SEX")
    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Basic
    @Column(name = "BIRTHDAY")
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Basic
    @Column(name = "REMARKS")
    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    @Basic
    @Column(name = "IS_MSG")
    public String getIsMsg() {
        return isMsg;
    }

    public void setIsMsg(String isMsg) {
        this.isMsg = isMsg;
    }

    @Basic
    @Column(name = "USER_PHONE")
    public Long getUserPhone() {
        return userPhone;
    }

    public void setUserPhone(Long userPhone) {
        this.userPhone = userPhone;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        User user = (User) o;
        return userNo == user.userNo &&
                Objects.equals(userName, user.userName) &&
                Objects.equals(sex, user.sex) &&
                Objects.equals(birthday, user.birthday) &&
                Objects.equals(remarks, user.remarks) &&
                Objects.equals(isMsg, user.isMsg) &&
                Objects.equals(userPhone, user.userPhone);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userNo, userName, sex, birthday, remarks, isMsg, userPhone);
    }

    @ManyToOne
    @JoinColumn(name = "PO_NO", referencedColumnName = "PO_NO")
    public Position getPosition() {
        return position;
    }

    public void setPosition(Position position) {
        this.position = position;
    }

    @ManyToOne
    @JoinColumn(name = "DEPT_NO", referencedColumnName = "DEPT_NO")
    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }
    @OneToMany(mappedBy = "userList")
    public Collection<Project> getProjectsByUserNo() {
        return projectsByUserNo;
    }

    public void setProjectsByUserNo(Collection<Project> projectsByUserNo) {
        this.projectsByUserNo = projectsByUserNo;
    }
    @OneToMany(mappedBy = "user")

    public Collection<Budget> getBudgetsByBId() {
        return budgetsByBId;
    }

    public void setBudgetsByBId(Collection<Budget> budgetsByBId) {
        this.budgetsByBId = budgetsByBId;
    }


    @Override
    public String toString() {
        return "User{" +
                "userNo=" + userNo +
                ", userName='" + userName + '\'' +
                ", sex='" + sex + '\'' +
                ", birthday=" + birthday +
                ", remarks='" + remarks + '\'' +
                ", isMsg='" + isMsg + '\'' +
                ", userPhone=" + userPhone +
                ", position=" + position +
                ", dept=" + dept +
                '}';
    }
}
